package jfinal42.cfg;

import jfinal42.ctrl.CategoryController;
import jfinal42.ctrl.NewsController;
import jfinal42.ctrl.UserController;
import jfinal42.inter.RoleInterceptor;
import jfinal42.model.Category;
import jfinal42.model.Comment;
import jfinal42.model.News;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.render.ViewType;
import com.jfinal.template.Engine;

public class NewsConfig extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		// TODO 自动生成的方法存根
		me.setDevMode(true);// 日志多一些
		me.setViewType(ViewType.JSP);// 默认视图是jsp格式
		super.loadPropertyFile("jdbc.properties");
	}

	@Override
	// 访问路径
	public void configRoute(Routes me) {

		me.add("/user", UserController.class);
		me.add("/news", NewsController.class);
		me.add("/cate", CategoryController.class);
		//
	}

	@Override
	public void configEngine(Engine me) {
		// TODO 自动生成的方法存根

	}

	@Override
	public void configPlugin(Plugins me) {
		// 数据源
		DruidPlugin dp = new DruidPlugin(super.getProperty("url"),
				super.getProperty("user"), super.getProperty("password"));
		me.add(dp);
		ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
		arp.setShowSql(true);
		me.add(arp);
		// 建立表和实体的对应关系
		arp.addMapping("category", Category.class);
		arp.addMapping("news", News.class);
		arp.addMapping("comment", Comment.class);
	}

	@Override
	// 拦截器
	public void configInterceptor(Interceptors me) {
		me.add(new RoleInterceptor());
	}

	@Override
	public void configHandler(Handlers me) {
		// TODO 自动生成的方法存根

	}

}
